<?php

declare(strict_types=1);

namespace App\CustHub\Model;

use Hyperf\Database\Model\Relations\BelongsToMany;
use Mine\MineModel;

/**
 * @property string $id 
 * @property string $corp_id 企业ID
 * @property int $robot_id 企微号ID
 * @property string $name 标签名称
 * @property string $group_id 分组ID：0的情况代表分组
 * @property int $label_type 标签类型：1=企业标签 2=个人标签
 * @property int $contact_cnt 客户数量
 * @property string $owner_id 拥有者微信ID
 * @property int $is_deleted 是否已删除 ：0=否 1=是
 * @property int $create_time 创建时间
 * @property int $data_type 
 * @property-read null|ChCorp $corp 
 * @property-read null|\Hyperf\Database\Model\Collection|ChContact[] $contacts 
 */
class ChCorpTag extends MineModel
{
    const OP_SAVE = 1;
    const OP_DELETE = 2;

    const OP_UPDATE = 3;

    public bool $incrementing = false;
    protected string $keyType = 'string';
    public bool $timestamps = false;
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'ch_corp_tag';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'corp_id', 'robot_id', 'name', 'group_id', 'label_type', 'contact_cnt', 'owner_id', 'is_deleted', 'create_time', 'data_type'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['robot_id' => 'integer', 'label_type' => 'integer', 'contact_cnt' => 'integer', 'is_deleted' => 'integer', 'create_time' => 'integer', 'data_type' => 'integer'];

    /**
     * 客户
     * @return BelongsToMany
     */
    public function contacts(): BelongsToMany
    {
        return $this->belongsToMany(ChContact::class, 'ch_contact_corp_tag', 'corp_tag_id', 'contact_id');
    }

    public function corp()
    {
        return $this->hasOne(ChCorp::class, 'id', 'corp_id');
    }
}
